﻿@using XStudio.XCRF.Web.Models.Enums
@model Hospital
@{
    ViewBag.Title = "HospitalMemberManage";
    Layout = "~/Views/Shared/Master.cshtml";
}

<h2>医院用户管理</h2>

@Model.Name<br />

@(Html.Telerik().Grid<Member>()
    .Name("HospitalMemberManageGrid")
    .ToolBar(config =>
    {
        if(LoginSession.IsAdministrator
          || (LoginSession.IsOwner && Model.ID == LoginSession.HospitalID))
            config.Custom().Name("AddResearcher").Text("添加研究人员")
                .Action<MemberController>(c => c.MemberAdd((byte)MemberTypes.Researcher, Model.ID));
    })
    .DataKeys(keys => keys.Add(member => member.ID))
    .Columns(columns =>
    {
        columns.Bound(member => member.LoginName).Title("登录名");
        columns.Bound(member => member.RealName).Title("真实姓名");
        columns.ForeignKey(member => member.Gender, GenderTypeInfo.SelectListItems, "Value", "Text").Title("性别");
        columns.ForeignKey(member => member.Type, MemberTypeInfo.SelectListItems, "Value", "Text").Title("用户类型");
        columns.Command(commands =>
        {
            commands.Custom("Detail").Text("查看详情").Ajax(true);
            if(!LoginSession.IsResearcher && LoginSession.HospitalID == Model.ID)
            commands.Delete();
        }).Title("操作");
    })
    .ClientEvents(events =>
    {
        events.OnCommand("OnCommand");
    })
    .DataBinding(bind => bind.Ajax()
        .Select<HospitalController>(c => c._HospitalMemberManage(Model.ID))
        .Delete<MemberController>(c => c._MemberDelete(null))
    ).Pageable(pager => pager.PageSize(10).Style(GridPagerStyles.NextPreviousAndNumeric))
    .Editable(edit => edit.Mode(GridEditMode.InLine))
)

<script type="text/javascript">
    function Detail(id) {
        var url = "@(Url.Action<MemberController>(c => c.MemberDetail(Guid.Empty)))";
        url = url.replace("@Guid.Empty", id);
        window.location = url;
    }
    function OnCommand(e) {
        switch (e.name) {
            case "Detail": Detail(e.dataItem.ID); break;
        }
    }
</script>